/*
* 问卷调查页面
* */

import {lazy, useEffect, useState} from "react";
import http from "../../request/request"
const Xuanzeti = lazy(async ()=>import("./xuanzeti"))
function wenjian() {
    const [xuanzelist,setxuanzelist] = useState([])
    // 向后台获取选择题列表
    const getxuanzelist = () => {
        http.getxuanze().then(res=>{
            if(res.data.success){
                const newlist = res.data.data.map(item=>{
                    return {...item,danxuan:"",duoxuan:[]}
                })
                setxuanzelist(newlist)
            }
        })
    }
    // 单选修改回调
    const danxuanchange = (yuansu,value) => {
        xuanzelist.forEach(item=>{
            if(item.index===yuansu.index){
                item.danxuan = value
            }
        })
        setxuanzelist([...xuanzelist])
    }
    // 多选回调
    const duoxuanchange = (yuansu,value) => {
        xuanzelist.forEach(item=>{
            if(item.index===yuansu.index){
                item.duoxuan = value
            }
        })
        setxuanzelist([...xuanzelist])
    }
    // 初始化的时候，先获取选择题列表
    useEffect(()=>{
        getxuanzelist()
    },[])
    return (
        <div className="w-full h-full flex flex-col justify-start items-center">
            <div className="w-4/5 flex flex-col justify-start items-center">
                <h1 className="w-full text-center my-5 text-3xl font-semibold">标题</h1>
                {xuanzelist.map((item,index)=>{
                    return <Xuanzeti neirong={item} key={item.index +"Xuanzeti"} danxuanchange={danxuanchange} duoxuanchange={duoxuanchange}/>
                })}
            </div>
        </div>
    )
}
export default wenjian